﻿
app.controller('VideoMonitorController', function ($scope, $http, $window, $compile, $filter, ipCookie, common, option, Upload) {
    $scope.result = {};
    $scope.dateOption = option.date;
    $scope.datetimeOption = option.datetime;

    //监控全局变量
    var g_iWndIndex = 0; //可以不用设置这个变量，有窗口参数的接口中，不用传值，开发包会默认使用当前选择窗口
    var g_oLocalConfig = null; //本地配置

    //错误码        
    //通用错误
    var ERROR_CODE_UNKNOWN = 1000; //未知错误
    var ERROR_CODE_NETWORKERROR = 1001; //网络错误
    var ERROR_CODE_PARAMERROR = 1002; //缺少插件元素

    //登录模块
    var ERROR_CODE_LOGIN_NOLOGIN = 2000; // 未登录
    var ERROR_CODE_LOGIN_REPEATLOGIN = 2001; //设备已登录，重复登录
    var ERROR_CODE_LOGIN_NOSUPPORT = 2002; //当前设备不支持Digest登录

    //预览播放
    var ERROR_CODE_PLAY_PLUGININITFAIL = 3000; //插件初始化失败
    var ERROR_CODE_PLAY_NOREPEATPLAY = 3001; //当前窗口已经在预览
    var ERROR_CODE_PLAY_PLAYBACKABNORMAL = 3002; //回放异常
    var ERROR_CODE_PLAY_PLAYBACKSTOP = 3003; //回放停止
    var ERROR_CODE_PLAY_NOFREESPACE = 3004; //录像过程中，硬盘容量不足

    //对讲
    var ERROR_CODE_TALK_FAIL = 5000; //语音对讲失败

    $scope.GetPlaceTree = function () {
        $scope.ParkTreeList = [];
        $http({
            method: 'POST',
            url: '../SafetyConfig/GetPlaceTree'
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                if (ret.Code == 100) {
                    $scope.ParkTreeList = ret.Data;
                    setTimeout(function () {
                        $('#tree-default').jstree({
                            "types": {
                                "default": {
                                    "icon": "fa fa-folder icon-state-warning icon-lg"
                                },
                                "file": {
                                    "icon": "fa fa-file icon-state-warning icon-lg"
                                }
                            },
                            "plugins": ["types"]
                        }).bind('click.jstree', function (event) {
                            var id = $(event.target).parents('li').attr('id');
                            if (id.indexOf('LINK') != -1) {
                                var roomid = $(event.target).parents('li').attr('data');
                                //点击事件
                            }

                        });
                    }, 1000);

                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });
    }

    $scope.GetCameraList = function (model, page) {
        $scope.DataLoading = true;
        $scope.CameraList = [];
        $http({
            method: 'POST',
            url: '../VideoMonitor/GetCameraPageList',
			params: { 'page': page }
        })
            .success(function (ret) {
                common.success($scope, null, ret);
                $scope.DataLoading = false;
                if (ret.Code == 100) {
                    $scope.CameraList = ret.Data.Data;
                }
                else {
                    alertify.alert(ret.Msg);
                }
            })
            .error(function (data, status, headers, config) {
                alertify.alert("请检查网络");
            });

    }

   
    $scope.OpenForm = function (model) {
        if (model.Type == 2) {
            window.open("HKVideo?id=" + model.Id, "_blank", 'width=800,height=600');
        }
        else if (model.Type == 1) {
            window.open("ZYVideo?id=" + model.Id, "_blank", 'width=800,height=600');
        }
    }

});